/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘柄华
 * Date: 2022-05-26
 * Time: 0:02
 */
import java.util.*;

public class TestDemo01{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        ListNode head = new ListNode(sc.nextInt());
        ListNode cur = head;
        for(int i=0;i<len-1;i++){
            cur.next = new ListNode(sc.nextInt());
            cur = cur.next;
        }
        int start = sc.nextInt();
        int end = sc.nextInt();
        ListNode cur1 = head;
        ListNode pre1 = null;
        ListNode cur2 = head;
        ListNode cur2Next = cur2.next;
        while(cur1!=null&&cur1.val!=start){
            pre1 = cur1;
            cur1 = cur1.next;
        }
        while(cur2.next!=null && cur2.val!=end){
            cur2 = cur2.next;
            cur2Next = cur2.next;
        }
        if(pre1==null){
            pre1 = reverse(cur1,cur2,cur2Next);
        }else{
            pre1.next = reverse(cur1,cur2,cur2Next);
        }

        while(pre1!=null){
            System.out.print(pre1.val+" ");
            pre1 = pre1.next;
        }
    }

    public static ListNode reverse(ListNode start,ListNode end,ListNode nt){
        Stack<ListNode> s = new Stack<>();
        while(start!=end){
            s.push(start);
            start = start.next;
        }
        ListNode next2 = end;
        while(!s.isEmpty()){
            next2.next = s.pop();
            next2 = next2.next;
        }
        next2.next = nt;

        return end;


    }
}

class ListNode{
    public int val;
    public ListNode next;
    public ListNode(int val){
        this.val = val;
    }
}
